/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ie.tcd.cs.railtickets.server.dao.impl;

import ie.tcd.cs.railtickets.server.dao.PathTimeDAO;
import ie.tcd.cs.railtickets.server.domain.PathTime;
import ie.tcd.cs.railtickets.server.domain.Ticket;
import ie.tcd.cs.railtickets.server.domain.TravelPath;
import java.util.List;
import static ie.tcd.cs.railtickets.server.dao.impl.HibernateSessionFactory.getSession;

/**
 *
 * @author Wenbo Sun
 */
public class PathTimeDAOImpl extends AbstractBaseDAOImpl implements PathTimeDAO{

    public List<PathTime> findByPath(TravelPath travelPath) {
        String query = "from PathTime pathTime where pathTime.path = ?";

        List<PathTime> result = getSession().createQuery(query).setParameter(0, travelPath).list();
        return result;
    }

    public PathTime findByTicket(Ticket ticket) {
        String query = "select ticket.pathTime from Ticket ticket where ticket = ?";
        PathTime pathTime = (PathTime) getSession().createQuery(query).setParameter(0, ticket).iterate().next();
        return pathTime;
    }

    

}
